<template>
  <a-select
    show-search
    placeholder="请选择"
    ref="select"
    :value="value"
    style="width: 100%"
    allow-clear
    @change="onChange"
  >
    <a-select-option v-for="item in options" :value="item.code">{{ item.name }}</a-select-option>
  </a-select>
</template>

<script setup lang="ts">
import { useUserStore } from '@/store'
import { DictItemDto } from '@/api/dict.ts'

const props = defineProps<{
  value: string | null
  dictCode: string
}>()
const emits = defineEmits(['update:value'])
const options = ref<DictItemDto[]>([])
const store = useUserStore()
const onChange = (value: string | null) => {
  emits('update:value', value)
}
onMounted(() => {
  options.value = store.dicts.find((i) => i.code === props.dictCode)?.items || []
})
</script>

<style scoped></style>
